package com.tjh.springbootapi.aspect;

import com.tjh.springbootapi.utils.ShaUtil;
import com.tjh.springbootapi.webSocket.ChannelSupervise;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Create by koala on 2022-08-14
 */
@Aspect
@Component
@Slf4j(topic = "needWebSocketAspect")
public class NeedWebSocketAspect {

    @Pointcut("@annotation(com.tjh.springbootapi.annotation.NeedWebSocket)")
    public void needWebSocketCut() {
    }

    @Around("needWebSocketCut()")
    public Object adapter(ProceedingJoinPoint point) throws Throwable {
        //用around，异常时不返回webSocket的key
        Object result = point.proceed();
        /*String girdKey = "userId" + "_" + new Date();
        String socketKey = ShaUtil.SHAEncrypt(girdKey);
        ChannelSupervise.socketKeyMap.put(socketKey, "userId");*/
        return result;
    }

}